package day10;

import java.io.IOException;
import java.net.InetAddress;

public class InetAddressDemo {
    public static void main(String[] args) throws IOException {
        // 获取百度
        InetAddress ia = InetAddress.getByName("www.baidu.com");


        // 打印字符串 ia:baidu.com/220.181.38.251
        System.out.println("ia:" + ia);

        // 切割字符串
        String[] split = ia.toString().split("/");

        System.out.println("域名:" + split[0]);
        System.out.println("ip:" + split[1]);

        // 判断
        boolean reachable = ia.isReachable(35);
        System.out.println("2毫秒内是否可达:" + reachable);

        // 请求地址
        InetAddress localHost = InetAddress.getLocalHost();
        System.out.println("localHost:" + localHost);
    }
}
